<?php
//var_dump($_GET);
//exit;
session_start();
$pgheader = "Signup munnau.com";
include('../_nconnect.php');
$pgheader = "Welcome to munnaU.com";

$emkey = $_GET["em_key"];
$emailn = $_GET["email"];
$_SESSION["email"] = $emailn;
//$emailn = "kalandrews@yahoo.co.jp";
$check_key = mysql_query("SELECT * FROM muemail_auth WHERE emailkey = '$emkey'");
if($check_key){
	$row_data = mysql_fetch_array($check_key);
	$emailx = $row_data['email'];
	$row_id = $row_data['id'];
}else{
	header('location: error.php');
}

$firstname=ucwords(strtolower($_POST['firstname']));
$lastname=ucwords(strtolower($_POST['lastname']));
$password=$_POST['password'];
$gender=$_POST['gender'];
$birthday_month=$_POST['birthday_month'];
$birthday_day=$_POST['birthday_day'];
$birthday_year=$_POST['birthday_year'];

//$emailx = "kalandrews@yahoo.co.jp";

/**Complete registration**/
if(isset($_POST['signup'])){
	$emailv = $_SESSION["email"];
	$password = md5($password);
	$ugtime_now = time() + (60*60*3);
	$date_time = date("Y-m-d H:i:s",$ugtime_now);
	$birthdate = date("Y-m-d",mktime(0,0,0,$birthday_month,$birthday_day,$birthday_year));
	$query="INSERT INTO mu_profiles (firstname, lastname, email, gender, birthday,joined)
	VALUES('$firstname','$lastname','$emailx','$gender','$birthdate','$date_time')";
	$query_run=mysql_query($query);
	if($query_run){
		$a_query=mysql_query("INSERT INTO mu_pass (uid_fk, password) VALUES( LAST_INSERT_ID(), '$password')");
		if($a_query){
			$del_q = mysql_query("DELETE FROM muemail_auth WHERE email = '$emailn'");
		}
		//session_start();
		//session_register('firstname');
		//session_start();
		//$_SESSION['email'] = $email;
		$_SESSION['firstname']=$firstname;
		//session_register('lastname');
		$_SESSION['lastname']=$lastname;
	}
	
	$uid_query = mysql_query("SELECT * FROM mu_profiles WHERE email = '$emailn'");
	while($row=mysql_fetch_array($uid_query)){
	//$row=mysql_fetch_array($id_query);
	//session_register('uid');
	$_SESSION['uid'] = $row['uid'];
	
	copy('prof_pics/mudefault500.png','prof_pics/500size/'.$_SESSION['uid'].'_propic.png');
	copy('prof_pics/mudefault150.png','prof_pics/150size/'.$_SESSION['uid'].'_propic.png');
	copy('prof_pics/mudefault50.png','prof_pics/50size/'.$_SESSION['uid'].'_propic.png');
	copy('prof_pics/mudefault40.png','prof_pics/40size/'.$_SESSION['uid'].'_propic.png');
	
	header('location: home.php');
	//echo "home.php";
	}
}
?>
<!--
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>

<link rel="stylesheet" type="text/css"  href="styles/styling.css"/>
<link rel="stylesheet" type="text/css" href="styles/nanoscroller.css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="scripts/jquery.nanoscroller.min.js"></script>
</head>
<body>
-->
<?php include("../Styles/_pageHeader.php"); ?>
	<div class=" cont_size_def">
    	<div id="signup_cont_form">
        	<h1><?php echo $_SESSION['email']; ?></h1>
            <hr />
            <h1>Complete registration</h1>
            <hr color="#FFFFFF">
            <form action="" method="post" id="signup_form">
                <table>
                <div id="signup_form_body">
                    
                    <div id="signup_form">
                        <tr>
                        <td><div class="sif_txt_fld">First Name:</div></td>
                        <td>
                            <input type="text" class="sif_input" name="firstname" id="firstname"/>
                        </td>
                        <td><span class="form_error" id="firstname_txt"></span></td>
                        </tr>
                        <tr>
                        <td><div class="sif_txt_fld">Last Name:</div></td>
                        <td>
                            <input type="text" class="sif_input" name="lastname" id="lastname"/>
                        </td>
                        <td><span class="form_error" id="lastname_txt"></span></td>
                        </tr>
                        <tr>
                        <td><div class="sif_txt_fld">Password:</div></td>
                        <td>
                            <input type="password" class="sif_input" name="password" id="password"/>
                        </td>
                        <td><span class="form_error" id="pass_txt"></span></td>
                        </tr>
                        <tr>
                        <td><div class="sif_txt_fld">Re-enter Password:</div></td>
                        <td>
                            <input type="password" class="sif_input" name="repassword" id="repassword"/>
                        </td>
                        <td><span class="form_error" id="repass_txt"></span></td>
                        </tr>
                        <tr>
                        <td><div class="sif_txt_fld">I am:</div></td>
                        <td>
                            <select class="sif_select" name="gender" id="gender">
                                <option value="0">Select Gender:</option>
                                <option value="1">Female</option>
                                <option value="2">Male</option>
                            </select>
                        </td>
                        <td><span class="form_error" id="gender_txt"></span></td>
                        </tr>
                        <tr>
                        <td><div class="sif_txt_fld">Birthday:</div></td>
                        <td><div class="sif_input_bx">
                            <select class="sif_select" name="birthday_month" id="birthday_month">
                                <option value="0">Month:</option>
                                <option value="1">Jan</option>
                                <option value="2">Feb</option>
                                <option value="3">Mar</option>
                                <option value="4">Apr</option>
                                <option value="5">May</option>
                                <option value="6">Jun</option>
                                <option value="7">Jul</option>
                                <option value="8">Aug</option>
                                <option value="9">Sep</option>
                                <option value="10">Oct</option>
                                <option value="11">Nov</option>
                                <option value="12">Dec</option>
                            </select>
                            <select class="sif_select" name="birthday_day" id="birthday_day">
                                <option value="0">Day:</option>
                                <option value="1">1</option>
                                <option value="2">2</option>
                                <option value="3">3</option>
                                <option value="4">4</option>
                                <option value="5">5</option>
                                <option value="6">6</option>
                                <option value="7">7</option>
                                <option value="8">8</option>
                                <option value="9">9</option>
                                <option value="10">11</option>
                                <option value="11">11</option>
                                <option value="12">12</option>
                                <option value="13">13</option>
                                <option value="14">14</option>
                                <option value="15">15</option>
                                <option value="16">16</option>
                                <option value="17">17</option>
                                <option value="18">18</option>
                                <option value="19">19</option>
                                <option value="20">20</option>
                                <option value="21">21</option>
                                <option value="22">22</option>
                                <option value="23">23</option>
                                <option value="24">24</option>
                                <option value="25">25</option>
                                <option value="26">26</option>
                                <option value="27">27</option>
                                <option value="28">28</option>
                                <option value="29">29</option>
                                <option value="30">30</option>
                                <option value="31">31</option>
                            </select>
                            <select class="sif_select" name="birthday_year" id="birthday_year">
                                <option value="0">Year:</option>
                                <option value="2012">2012</option>
                                <option value="2011">2011</option>
                                <option value="2010">2010</option>
                                <option value="2009">2009</option>
                                <option value="2008">2008</option>
                                <option value="2007">2007</option>
                                <option value="2006">2006</option>
                                <option value="2005">2005</option>
                                <option value="2004">2004</option>
                                <option value="2003">2003</option>
                                <option value="2002">2002</option>
                                <option value="2001">2001</option>
                                <option value="2000">2000</option>
                                <option value="1999">1999</option>
                                <option value="1998">1998</option>
                                <option value="1997">1997</option>
                                <option value="1996">1996</option>
                                <option value="1995">1995</option>
                                <option value="1994">1994</option>
                                <option value="1993">1993</option>
                                <option value="1992">1992</option>
                                <option value="1991">1991</option>
                                <option value="1990">1990</option>
                                <option value="1989">1989</option>
                                <option value="1988">1988</option>
                                <option value="1987">1987</option>
                                <option value="1986">1986</option>
                                <option value="1985">1985</option>
                                <option value="1984">1984</option>
                                <option value="1983">1983</option>
                                <option value="1982">1982</option>
                                <option value="1981">1981</option>
                                <option value="1980">1980</option>
                                <option value="1979">1979</option>
                                <option value="1978">1978</option>
                                <option value="1977">1977</option>
                                <option value="1976">1976</option>
                                <option value="1975">1975</option>
                                <option value="1974">1974</option>
                                <option value="1973">1973</option>
                                <option value="1972">1972</option>
                                <option value="1971">1971</option>
                                <option value="1970">1970</option>
                                <option value="1969">1969</option>
                                <option value="1968">1968</option>
                                <option value="1966">1967</option>
                                <option value="1966">1966</option>
                                <option value="1965">1965</option>
                                <option value="1964">1964</option>
                                <option value="1963">1963</option>
                                <option value="1962">1962</option>
                                <option value="1961">1961</option>
                                <option value="1960">1960</option>
                                <option value="1959">1959</option>
                                <option value="1958">1958</option>
                                <option value="1957">1957</option>
                                <option value="1956">1956</option>
                                <option value="1955">1955</option>
                                <option value="1954">1954</option>
                                <option value="1953">1953</option>
                                <option value="1952">1952</option>
                                <option value="1951">1951</option>
                                <option value="1950">1950</option>
                                <option value="1949">1949</option>
                                <option value="1948">1948</option>
                                <option value="1947">1947</option>
                                <option value="1946">1946</option>
                                <option value="1945">1945</option>
                                <option value="1944">1944</option>
                                <option value="1943">1943</option>
                                <option value="1942">1942</option>
                                <option value="1941">1941</option>
                                <option value="1940">1940</option>
                                <option value="1939">1939</option>
                                <option value="1938">1938</option>
                                <option value="1937">1937</option>
                                <option value="1936">1936</option>
                                <option value="1935">1935</option>
                                <option value="1934">1934</option>
                                <option value="1933">1933</option>
                                <option value="1932">1932</option>
                                <option value="1931">1931</option>
                                <option value="1930">1930</option>
                                <option value="1929">1929</option>
                                <option value="1928">1928</option>
                                <option value="1927">1927</option>
                                <option value="1926">1926</option>
                                <option value="1925">1925</option>
                                <option value="1924">1924</option>
                                <option value="1923">1923</option>
                                <option value="1922">1922</option>
                                <option value="1921">1921</option>
                                <option value="1920">1920</option>
                                <option value="1919">1919</option>
                                <option value="1918">1918</option>
                                <option value="1917">1917</option>
                                <option value="1916">1916</option>
                                <option value="1915">1915</option>
                                <option value="1914">1914</option>
                                <option value="1913">1913</option>
                                <option value="1912">1912</option>
                                <option value="1911">1911</option>
                                <option value="1910">1910</option>
                                <option value="1909">1909</option>
                                <option value="1908">1908</option>
                                <option value="1907">1907</option>
                                <option value="1906">1906</option>
                                <option value="1905">1905</option>
                                <option value="1904">1904</option>
                                <option value="1903">1903</option>
                                <option value="1902">1902</option>
                                <option value="1901">1901</option>
                                <option value="1900">1900</option>
                            </select>
                        </div></td>
                        <td><span class="form_error" id="birthday_txt"></span></td>
                        </tr>
                        <tr>
                        <td><div class="sif_txt_fld">Phone Number:</div></td>
                        <td>
                        	<input type="text" class="sif_input" name="phone_no" id="phone_no"/>
                        </td>
                        </tr>
                        <tr>
                        <td></td>
                        <td>
                        	<input id="submit_form_btn" class="signup_btn_in" type="submit" name="signup" value="Submit Form" />
                        </td>
                        </tr>
                        
                    </div>
                
                
                </div>
                </table>
            </form>
            <hr color="#FFFFFF">
            <br/>
        </div>
    </div>
<?php include("../_pageFooter.html") ?>
<script type="text/javascript">
	$(document).ready(function() {
		/**Get URL Variables**/
		var QueryString = function () {
		  // This function is anonymous, is executed immediately and 
		  // the return value is assigned to QueryString!
		  var query_string = {};
		  var query = window.location.search.substring(1);
		  var vars = query.split("&");
		  for (var i=0;i<vars.length;i++) {
			var pair = vars[i].split("=");
				// If first entry with this name
			if (typeof query_string[pair[0]] === "undefined") {
			  query_string[pair[0]] = pair[1];
				// If second entry with this name
			} else if (typeof query_string[pair[0]] === "string") {
			  var arr = [ query_string[pair[0]], pair[1] ];
			  query_string[pair[0]] = arr;
				// If third or later entry with this name
			} else {
			  query_string[pair[0]].push(pair[1]);
			}
		  } 
			return query_string;
		} ();
		/****/
		$("#LogSign_cont").hide();
		var get_email = "<?php echo $_GET["email"] ; ?>";
		$("#acct_siteInfo_cont").html("<div class='user_details'>Hello <br/> " + get_email + "</div>");
        $("#submit_form_btn").click(function(){
			var firstname = $("#firstname").val();
			var lastname = $("#lastname").val();
			var pass = $("#password").val();
			var repass = $("#repassword").val();
			var gender = $("#gender").val();
			var bday = $("#birthday_day").val();
			var bmonth = $("#birthday_month").val();
			var byear = $("#birthday_year").val();
			if($.trim(firstname)==""){
				$("#firstname_txt").html("Please input your firstname");
			}else{ $("#firstname_txt").html(""); }
			if($.trim(lastname)==""){
				$("#lastname_txt").html("Please input your lastname");
			}else{ $("#lastname_txt").html(""); }
			if($.trim(pass)==""){
				$("#pass_txt").html("Please input a password");
			}else{ $("#pass_txt").html("");}
			if($.trim(repass)==""){
				$("#repass_txt").html("Please re-enter the password");
			}else{ $("#repass_txt").html("");}
			if(gender =="0"){
				$("#gender_txt").html("Please select your gender");
			}else{ $("#gender_txt").html("");}
			if(bday =="0"){
				$("#birthday_txt").html("Please select your birthday month and year");
			}else{ $("#birthday_txt").html("");}
			if(bmonth =="0"){
				$("#birthday_txt").html("Please select your birthday month and year");
			}else{ $("#birthday_txt").html("");}
			if(byear =="0"){
				$("#birthday_txt").html("Please select your birthday month and year");
			}else{ $("#birthday_txt").html("");}
			
			if($.trim(pass) != $.trim(repass)){
				$("#repass_txt").html("Passwords don't match");
			}else{
				if($.trim(firstname)!="" && $.trim(lastname)!="" && bday !="0" && bmonth !="0" && byear !="0"){
					return true;
				}
			}
		return false;
		});
    });
</script>
<!--
</body>
</html>
-->